package net.wanho.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import net.wanho.entity.User;
import net.wanho.service.UserService;
import org.springframework.web.bind.annotation.*;

/**
 * Author：汤小洋
 * Date：2024-08-13 17:05
 * Description：<描述>
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @PostMapping
    public User add(@RequestBody User user){
        userService.add(user);
        return user;
    }

    @GetMapping("/findPage")
    public PageInfo<User> findPage(@RequestParam(required = false, defaultValue = "1") int pageNum,
                                   @RequestParam(required = false, defaultValue = "5") int pageSize){
        PageInfo<User> pageInfo = userService.findPage(pageNum, pageSize);
        return pageInfo;
    }

    @GetMapping("/transfer")
    public String transfer(int money){
        userService.transfer(money);
        return "success";
    }

}
